home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / window.c < prev   
C/C++ Source or Header  |  1979-12-31  |  9KB  |  404 lines

  1. /* --------------------------------- window.c ------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Manage the different windows.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. extern void FAR
  14. windows_term (void)
  15. {
  16.     int    i;
  17.  
  18.     for (i = 0; i < NHDD; ++i) {
  19.         if (!(st.hdd[i].flags & HDF_ON))
  20.             continue;
  21.         st.hdd[i].type = HDT_NONE;
  22.         st.hdd[i].flags = 0;
  23.         DEL0 (st.hdd[i].view.window);
  24.         DEL0 (st.hdd[i].view.viewport);
  25.         st.hdd[i].view.screen = 0;
  26.     }
  27. }
  28.  
  29. LOCAL_FUNC void NEAR
  30. window_set (int i, int type, int orgx, int orgy, int maxx, int maxy)
  31. {
  32.     WINDOW    *w;
  33.  
  34.     if (i < 0)
  35.         w = CW;
  36.     else if (T(w = NEW (st.hdd[i].view.window))) {
  37.         st.hdd[i].type = type;
  38.         st.hdd[i].flags = HDF_ON;
  39.         st.hdd[i].view.viewport = 0;
  40.         st.hdd[i].view.screen = CS;
  41.         st.hdd[i].FgColor = CC_WHITE;
  42.         st.hdd[i].BgColor = CC_BLACK;
  43.         st.hdd[i].BoColor = CC_LGRAY;
  44.  
  45.     } else
  46.         return;
  47.     w->orgx = orgx;
  48.     w->orgy = orgy;
  49.     w->maxx = maxx;
  50.     w->maxy = maxy;
  51.     if (i < 0 && VIS_STEREOSCOPIC == st.stereo)
  52.         set_small_frame ();
  53. }
  54.  
  55. extern void FAR
  56. windows_set (void)
  57. {
  58.     windows_term ();
  59.  
  60.     switch (st.windows) {
  61.     case WIN_LANDSCAPE:
  62.         window_set (-1, 0,         FONE/2,   FONE/3,   FONE/2, FONE/3);
  63.         window_set ( 0, HDT_STORES,FONE/8,   FONE/6*5, FONE/8, FONE/6);
  64.         window_set ( 1, HDT_MIRROR,FONE/2,   FONE/6*5, FONE/4, FONE/6);
  65.         window_set ( 3, HDT_RADAR, FONE/8*7, FONE/6*5, FONE/8, FONE/6);
  66.         break;
  67.     case WIN_PORTRATE:
  68.         window_set (-1, 0,         FONE/3,   FONE/2,   FONE/3, FONE/2);
  69.         window_set ( 0, HDT_REAR,  FONE/6*5, FONE/3,   FONE/6, FONE/3);
  70.         window_set ( 1, HDT_RADAR, FONE/6*5, FONE/6*5, FONE/6, FONE/6);
  71.         break;
  72.     case WIN_SQUARE:
  73.         window_set (-1, 0,         FONE/8*3, FONE/2, FONE/8*3, FONE/2);
  74.         window_set ( 0, HDT_REAR,  FONE/8*7, FONE/6,   FONE/8, FONE/6);
  75.         window_set ( 1, HDT_PAN,   FONE/8*7, FONE/6*3, FONE/8, FONE/6);
  76.         window_set ( 2, HDT_RADAR, FONE/8*7, FONE/6*5, FONE/8, FONE/6);
  77.         break;
  78.     case WIN_WIDE:
  79.         window_set (-1, 0,         FONE/2,   FONE/3,   FONE/2, FONE/3);
  80.         window_set ( 0, HDT_REAR,  FONE/8,   FONE/6*5, FONE/8, FONE/6);
  81.         window_set ( 1, HDT_STORES,FONE/8*3, FONE/6*5, FONE/8, FONE/6);
  82.         window_set ( 2, HDT_PAN,   FONE/8*5, FONE/6*5, FONE/8, FONE/6);
  83.         window_set ( 3, HDT_RADAR, FONE/8*7, FONE/6*5, FONE/8, FONE/6);
  84.         break;
  85.     case WIN_PANORAMA:
  86.         window_set (-1, 0,         FONE/6*3, FONE/3,   FONE/6, FONE/3);
  87.         window_set ( 0, HDT_LEFT,  FONE/6*1, FONE/3,   FONE/6, FONE/3);
  88.         window_set ( 1, HDT_RIGHT, FONE/6*5, FONE/3,   FONE/6, FONE/3);
  89.         window_set ( 2, HDT_REAR,  FONE/8,   FONE/6*5, FONE/8, FONE/6);
  90.         window_set ( 3, HDT_STORES,FONE/8*3, FONE/6*5, FONE/8, FONE/6);
  91.         window_set ( 4, HDT_PAN,   FONE/8*5, FONE/6*5, FONE/8, FONE/6);
  92.         window_set ( 5, HDT_RADAR, FONE/8*7, FONE/6*5, FONE/8, FONE/6);
  93.         break;
  94.     case WIN_ETHER:
  95.         window_set (-1, 0,        FCON(0.50),    FCON(.30),
  96.                         FCON(0.485),    FCON(.28));
  97.         window_set ( 0, HDT_STORES,    FCON(0.17),    FCON(.80),
  98.                         FCON(0.17),    FCON(.20));
  99.         window_set ( 1, HDT_RADAR,    FCON(0.51),    FCON(.80),
  100.                         FCON(0.17),    FCON(.20));
  101.         window_set ( 2, HDT_PAN,    FCON(0.84),    FCON(.87),
  102.                         FCON(0.16),    FCON(.13));
  103.         window_set ( 3, HDT_LAMPS,    FCON(0.84),    FCON(.67),
  104.                         FCON(0.16),    FCON(.07));
  105.         window_set ( 4, HDT_NONE,    FCON(0.50),    FCON(.30),
  106.                         FCON(0.50),    FCON(.30));
  107.         break;
  108.     case WIN_FULL:
  109.     default:
  110.         window_set (-1, 0,         FONE/2,   FONE/2,   FONE/2, FONE/2);
  111.         break;
  112.     }
  113.     win_setup ();
  114. }
  115.  
  116. extern void FAR
  117. set_screen (int sizex, int sizey)
  118. {
  119.     if (CS->device->sizex && CS->device->sizey) {
  120.         CS->device->lengx = muldiv (CS->device->lengx, sizex,
  121.                         CS->device->sizex);
  122.         CS->device->lengy = muldiv (CS->device->lengy, sizey,
  123.                         CS->device->sizey);
  124.     }
  125.  
  126.     CS->device->sizex = sizex;
  127.     CS->device->sizey = sizey;
  128.  
  129.     CS->sizex = (CS->device->sizex-3)/2*2+1;
  130.     CS->minx = sizex - CS->sizex - 2;
  131.  
  132.     CS->sizey = (CS->device->sizey-3)/2*2+1;
  133.     CS->miny = 1;
  134. }
  135.  
  136. LOCAL_FUNC void NEAR
  137. adjust_viewports (void)
  138. {
  139.     int        t;
  140.     OBJECT        *v;
  141.     VIEWPORT    *vp;
  142.  
  143. /* Adjust all viewports to main window's aspect ratio. This adjustment is
  144.  * necessary because the main window and the main viewport are correctly
  145.  * adjusted at all times. When selecting an external-view the viewports are
  146.  * swapped, and if the new viewport has the wrong aspect ratio then the
  147.  * main view is distorted. Note that HDD displays dynamicaly adjust the
  148.  * aspect ratios just before using it [views.c: show_view()].
  149. */
  150.     for (v = CO; v; v = v->next) {
  151.         if (T(vp = v->viewport) && vp != CP) {
  152.             vp->maxx  = CP->maxx;
  153.             vp->maxy  = CP->maxy;
  154.             vp->distz = CP->distz;
  155.             vp->x     = CP->x;
  156.             vp->y     = CP->y;
  157.             t = vp->zoom - CP->zoom;
  158.             vp->zoom  = CP->zoom;
  159.             zoom (vp, t);
  160.         }
  161.     }
  162. }
  163.  
  164. /* Set the viewport parameters. These are always relative to the main
  165.  * screen/window.
  166. */
  167. LOCAL_FUNC void NEAR
  168. set_viewport (VIEWPORT *vp)
  169. {
  170.     int    tx, ty;
  171.  
  172.     if (CS->device->lengx == 0 || CS->device->lengy == 0) {
  173.         LogPrintf ("null viewport\n");
  174.         die ();
  175.     }
  176.     tx = fmul (CS->sizex, CW->maxx);
  177.     tx = muldiv (FONE, tx, CS->device->sizex);
  178.     ty = fmul (CS->sizey, CW->maxy);
  179.     ty = muldiv (FONE, ty, CS->device->sizey);
  180.     if (CS->device->lengx > CS->device->lengy)
  181.         ty = muldiv (ty, CS->device->lengy, CS->device->lengx);
  182.     else
  183.         tx = muldiv (tx, CS->device->lengx, CS->device->lengy);
  184.  
  185.     vp->maxx = tx;            /* maps world to viewport */
  186.     vp->maxy = ty;
  187.     vp->distz = 1*VONE*VONE;
  188. #if 0
  189.     if (tx < ty)
  190.         vp->z = 2*tx;        /* 45 degrees view in x */
  191.     else
  192.         vp->z = 2*ty;        /* 45 degrees view in y */
  193. #else
  194.     vp->z = 2*tx;            /* always 45 degrees view in x */
  195. #endif
  196.     vp->x = 0*FONE;            /* viewer at center */
  197.     vp->y = 0*FONE;
  198.     vp->zoom = 0;
  199. }
  200.  
  201. extern void FAR
  202. set_main (void)
  203. {
  204.     int    i;
  205.  
  206.     set_screen (CS->device->sizex, CS->device->sizey);
  207.     windows_set ();
  208.     i = CP->zoom;
  209.     set_viewport (CP);
  210.     zoom (CP, i);
  211.     adjust_viewports ();
  212. }
  213.  
  214. extern void FAR
  215. set_small_frame (void)
  216. {
  217.     CW->orgx -= CW->maxx;        /* left frame */
  218.     CW->maxx = muldiv (CW->maxx, st.gap-1, 2*st.gap);
  219.     CW->orgx += CW->maxx;
  220.  
  221.     CP->maxx = muldiv (CP->maxx, st.gap-1, 2*st.gap);
  222.     CP->z     = muldiv (CP->z, st.gap-1, 2*st.gap);
  223.  
  224.     adjust_viewports ();
  225. }
  226.  
  227. extern void FAR
  228. set_large_frame (void)
  229. {
  230.     CW->orgx -= CW->maxx;
  231.     if (CW->maxx > FONE/2)
  232.         CW->maxx = FONE;
  233.     else
  234.         CW->maxx = muldiv (CW->maxx, 2*st.gap, st.gap-1);
  235.     CW->orgx += CW->maxx;
  236.  
  237.     if (CP->maxx > FONE/2)
  238.         CP->maxx = FONE;
  239.     else
  240.         CP->maxx = muldiv (CP->maxx, 2*st.gap, st.gap-1);
  241.     if (CP->z > FONE/2)
  242.         CP->z = FONE;
  243.     else
  244.         CP->z = muldiv (CP->z, 2*st.gap, st.gap-1);
  245.  
  246.     adjust_viewports ();
  247. }
  248.  
  249.  
  250. #define    ZOOMIN        FCON(1.26)    /* cubic root of 2.0 */
  251. #define    ZOOMOUT        FCON(1/1.26)
  252.  
  253. extern void FAR
  254. zoom (VIEWPORT *vp, int zoom)
  255. {
  256.     if (!vp || !zoom)
  257.         return;
  258.  
  259.     zoom += vp->zoom;
  260.     set_viewport (vp);
  261.  
  262.     for (; zoom > 0; ++vp->zoom, --zoom) {
  263.         if (vp->z < ZOOMOUT && vp->distz < VMAX/2) {
  264.             vp->z = fmul (vp->z, ZOOMIN);
  265.             vp->distz = fmul (vp->distz, ZOOMIN);
  266.         } else if (vp->maxx > FONE/128 && vp->maxy > FONE/128) {
  267.             vp->maxx = fmul (vp->maxx, ZOOMOUT);
  268.             vp->maxy = fmul (vp->maxy, ZOOMOUT);
  269.         } else
  270.             break;
  271.     }
  272.  
  273.     for (; zoom < 0; --vp->zoom, ++zoom) {
  274.         if (vp->maxx < ZOOMOUT && vp->maxy < ZOOMOUT) {
  275.             vp->maxx = fmul (vp->maxx, ZOOMIN);
  276.             vp->maxy = fmul (vp->maxy, ZOOMIN);
  277.         } else if (vp->z > FONE/128 &&  vp->distz > VONE) {
  278.             vp->z = fmul (vp->z, ZOOMOUT);
  279.             vp->distz = fmul (vp->distz, ZOOMOUT);
  280.         } else
  281.             break;
  282.     }
  283. }
  284.  
  285. #undef ZOOMIN
  286. #undef ZOOMOUT
  287.  
  288. extern int FAR
  289. window_select (void)
  290. {
  291.     int    ch;
  292.     int    save_flags1;
  293.     HMSG    *m;
  294.  
  295.     if (st.flags1 & SF_EXTVIEW) {
  296.         MsgEPrintf (50, "Exit ExtView!");
  297.         return (-1);
  298.     }
  299.     save_flags1 = st.flags1 & SF_IDENT;
  300.     st.flags1 |= SF_IDENT;
  301.     for (;;) {
  302.         m = MsgWPrintf (0, "Which window?");
  303.         ch = mgetch ();
  304.         msg_del (m);
  305.         if (KF_ESC == ch || K_ENTER == ch) {
  306.             ch = -1;
  307.             break;
  308.         }
  309.         ch -= '0';
  310.         if (ch >= 0 && ch <= NHDD &&
  311.             (!ch || st.hdd[ch-1].flags & HDF_ON))
  312.             break;
  313.     }
  314.     st.flags1 &= ~SF_IDENT;
  315.     st.flags1 |= save_flags1;
  316.     return (ch);
  317. }
  318.  
  319. static MENU MenuWin[] = {
  320.     {'c', "configure"},    /*  0 */
  321.     {'b', "bg color"},    /*  1 */
  322.     {'f', "fg color"},    /*  2 */
  323.     {'o', "bo color"},    /*  3 */
  324.     {'1', "full"},        /*  4 */
  325.     {'2', "landscape"},    /*  5 */
  326.     {'3', "portrait"},    /*  6 */
  327.     {'4', "square"},    /*  7 */
  328.     {'5', "wide"},        /*  8 */
  329.     {'6', "panorama"},    /*  9 */
  330.     {'e', "ether"},        /* 10 */
  331. {'\0', 0}};
  332.  
  333. extern int FAR
  334. menu_windows (void)
  335. {
  336.     int    sel, i, ret;
  337.     int    hdd;
  338.     Ushort    *item;
  339.  
  340.     for (ret = 0; !ret;) {
  341.         sel = menu_open (MenuWin, st.windows+3);
  342.  
  343.         switch (sel) {
  344.         case MENU_ABORTED:
  345.         case MENU_FAILED:
  346.             ret = 1;
  347.             break;
  348.         case 0:
  349.         case 1:
  350.         case 2:
  351.         case 3:
  352.             for (;;) {
  353.             hdd = window_select ();
  354.             if (hdd < 0)
  355.                 break;
  356.             if (0 == sel) {
  357.                 i = hdd ? st.hdd[hdd-1].type : st.extview;
  358.                 i = menu_view (i);
  359.                 if (i >= 0) {
  360.                     if (hdd)
  361.                         st.hdd[hdd-1].type = i;
  362.                     else
  363.                         st.extview = i;
  364.                 }
  365.             } else {
  366.                 switch (sel) {
  367.                 default:
  368.                 case 1:
  369.                     item = hdd ? &st.hdd[hdd-1].BgColor
  370.                                 : &CS->BgColor;
  371.                     break;
  372.                 case 2:
  373.                     item = hdd ? &st.hdd[hdd-1].FgColor
  374.                                 : &CS->FgColor;
  375.                     break;
  376.                 case 3:
  377.                     item = hdd ? &st.hdd[hdd-1].BoColor
  378.                                 : &CS->BoColor;
  379.                     break;
  380.                 }
  381.                 color_assign (item);
  382.             }
  383.             }
  384.             ret = 1;
  385.             break;
  386.         default:
  387.             sim_set ();
  388.             screen_empty ();
  389.  
  390.             st.windows = sel - 3;
  391.             set_main ();
  392.  
  393.             screen_start ();
  394.  
  395.             sim_reset ();
  396.             break;
  397.         }
  398.         if (MENU_FAILED != sel)
  399.             menu_close ();
  400.     }
  401.  
  402.     return (0);
  403. }
  404.